<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Element 案例</title>
    <script src="js/vue.js"></script>
    <script src="element-ui/lib/index.js"></script>
    <link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
    <style>
        .el-table .warning-row {
            background: oldlace;
        }

        .el-table .success-row {
            background: #f0f9eb;
        }
    </style>
</head>
<body>

<div id="app">
    <!--第一行-->
    <el-row>
        <el-form :inline="true" :model="searchBrand" class="demo-form-inline">
            <el-form-item label="当前状态">
                <el-select v-model="searchBrand.status" placeholder="当前状态">
                    <el-option label="禁用" value="0"></el-option>
                    <el-option label="启用" value="1"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="企业名称">
                <el-input v-model="searchBrand.companyName" placeholder="企业名称"></el-input>
            </el-form-item>
            <el-form-item label="品牌名称">
                <el-input v-model="searchBrand.brandName" placeholder="品牌名称"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
            </el-form-item>
        </el-form>
    </el-row>

    <!--第二行-->
    <el-row>
        <el-button type="danger" plain>批量删除</el-button>
        <el-button type="primary" plain @click="dialogVisible = true">新增</el-button>
    </el-row>
    <!--对话框-->
    <el-dialog
            title="编辑品牌"
            :visible.sync="dialogVisible"
            width="30%">
        <!--对话框里面的表单-->
        <el-form :model="addBrand" :rules="rules" ref="addBrand" label-width="100px" class="demo-ruleForm">
            <el-form-item label="品牌名称" prop="brandName">
                <el-input v-model="addBrand.brandName"></el-input>
            </el-form-item>
            <el-form-item label="企业名称" prop="companyName">
                <el-input v-model="addBrand.companyName"></el-input>
            </el-form-item>
            <el-form-item label="排序">
                <el-input v-model="addBrand.ordered"></el-input>
            </el-form-item>
            <el-form-item label="备注">
                <el-input type="textarea" v-model="addBrand.description"></el-input>
            </el-form-item>
            <el-form-item label="状态">
                <el-switch v-model="addBrand.status"></el-switch>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
                <el-button @click="resetForm('ruleForm')">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>

    <!--第三行-->
    <el-row>
        <template>
            <el-table
                    :data="tableData"
                    style="width: 100%"
                    :row-class-name="tableRowClassName"
                    @selection-change="handleSelectionChange">
                <el-table-column
                        type="selection"
                        width="55">
                </el-table-column>
                <el-table-column
                        type="index"
                        width="50">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="brandName"
                        label="品牌名称">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="companyName"
                        label="企业名称">
                </el-table-column>
                <el-table-column
                        prop="ordered"
                        label="排序"
                        width="150">
                </el-table-column>
                <el-table-column
                        prop="status"
                        label="当前状态"
                        width="150">
                </el-table-column>
                <el-table-column label="操作" width="250">
                    <template slot-scope="scope">
                        <el-button
                                size="mini"
                                type="primary"
                                @click="handleEdit(scope.$index, scope.row)">修改
                        </el-button>
                        <el-button
                                size="mini"
                                type="danger"
                                @click="handleDelete(scope.$index, scope.row)">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </template>
    </el-row>

    <!--第四行-->
    <el-row>
        <div class="block" style="text-align: center; margin-top: 15px">
            <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[5, 10, 15, 20]"
                    :page-size="5"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="400">
            </el-pagination>
        </div>
    </el-row>
</div>

<script>
    new Vue({
        el: "#app",
        methods: {
            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },
            // 多选按钮状态改变会调用
            handleSelectionChange(val) {
                this.multipleSelection = val;
                console.log(this.multipleSelection);
            },
            // 点击查询按钮时调用
            onSubmit() {
                console.log('准备查询: ' + this.searchBrand);
            },
            submitForm(formName) {
                alert("提交!")
            },
            resetForm(formName) {
                // 关闭对话框
                this.dialogVisible = false;
            },
            // 每页数量发生变化调用
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            // 页码变化调用
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
            }
        },
        data() {
            return {
                // 分页工具条,显示当前第几页
                currentPage: 2,
                addBrand: {
                    brandName: '',
                    companyName: '',
                    ordered: '',
                    description: '',
                    status: "0"
                },
                rules: {
                    brandName: [
                        { required: true, message: '请输入品牌名称', trigger: 'blur' },
                        { min: 1, max: 15, message: '品牌名称长度在 1 到 15 个字符', trigger: 'blur' }
                    ],
                    companyName: [
                        { required: true, message: '请输入企业名称', trigger: 'blur' },
                        { min: 2, max: 15, message: '企业名称长度在 2 到 15 个字符', trigger: 'blur' }
                    ]
                },
                // 控制对话框是否显示true表示显示,false表示不显示
                dialogVisible: false,
                // 第一行表单绑定的数据
                searchBrand: {
                    brandName: '',
                    companyName: '',
                    status: "0"
                },
                // 保存选中的数据
                multipleSelection: [],
                tableData: [{
                    brandName: '华为P50',
                    companyName: '华为科技有限公司',
                    ordered: '1',
                    status: '1'
                },
                    {
                        brandName: '华为P51',
                        companyName: '华为科技有限公司',
                        ordered: '1',
                        status: '1'
                    },
                    {
                        brandName: '华为P52',
                        companyName: '华为科技有限公司',
                        ordered: '1',
                        status: '1'
                    },
                    {
                        brandName: '华为P53',
                        companyName: '华为科技有限公司',
                        ordered: '1',
                        status: '1'
                    }]
            }
        }
    });
</script>
</body>
</html>